package com.dysoft.flesh.gl;

import com.dysoft.flesh.RenderContext;
import com.dysoft.flesh.Renderer;

import javax.media.opengl.GL;
import javax.media.opengl.GLContext;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.Callable;

/**
 * @author Sean Micklethwaite
 *         Aug 16, 2010 6:10:32 PM
 */
public class GLObject {
	final static Queue<Renderer.Operation> dtors = new ArrayDeque<Renderer.Operation>();

	final protected int handle;

	public GLObject(int handle) {
		this.handle = handle;
	}

	public int getHandle() {
		return handle;
	}

	public static void runDtors(RenderContext ctx) {
		if(dtors.isEmpty()) return;
		synchronized (dtors) {
			for(Renderer.Operation dtor : dtors) {
				try {
					dtor.call(ctx);
				} catch (Exception e) {
				}
			}
			dtors.clear();
		}
	}
	protected static void dtor(Renderer.Operation dtor) {
		synchronized (dtors) {
			dtors.add(dtor);
		}
	}
}
